FROM {{ namespace }}/{{ image_prefix }}sensu-base:{{ tag }}
{% block labels %}
LABEL maintainer="{{ maintainer }}" name="{{ image_name }}" build-date="{{ build_date }}"
{% endblock %}

{% block sensu_client_header %}{% endblock %}

{% import "macros.j2" as macros with context %}

{{ macros.enable_extra_repos(['ceph']) }}

{% if base_package_type == 'rpm' %}
    {% set sensu_client_packages = [
        'ceph-common',
        'cyrus-sasl-devel',
        'docker-client',
        'gcc-c++',
        'make',
        'mariadb',
        'ntp',
        'python3-pymongo',
        'ruby-devel'
    ] %}
{% elif base_package_type == 'deb' %}
    {% set sensu_client_packages = [
        'build-essential',
        'ceph-common',
        'docker.io',
        'inetutils-ping',
        'libsasl2-dev',
        'mysql-client',
        'ntp',
        'python3-cephfs',
        'python3-pymongo',
        'python3-rados',
        'python3-rbd'
    ] %}
{% else %}
RUN echo '{{ image_name }} not yet available for {{ base_distro }}' \
    && /bin/false
{% endif %}

{{ macros.install_packages(sensu_client_packages | customizable("packages")) }}

{% block sensu_clients_install %}

# Sensu plugins are all using semantic versioning.
# Let's cap them to the known major version that works with the ruby shipped on
# rhel/centos (currently 2.0)
{% set sensu_plugins = [
    'cpu-checks:"~>1"',
    'disk-checks:"~>2"',
    'dns:"~>1"',
    'docker:"~>3"',
    'elasticsearch:"~>1"',
    'filesystem-checks:"~>1"',
    'haproxy:"~>1"',
    'http:"~>1"',
    'io-checks:"~>1"',
    'load-checks:"~>3"',
    'memcached:"~>0"',
    'memory-checks:"~>1"',
    'mongodb:"~>0"',
    'mysql:"~>2"',
    'network-checks:"~>2"',
    'ntp:"~>1"',
    'openstack:"~>1"',
    'rabbitmq:"~>3"',
    'redis:"~>2"',
    'uptime-checks:"~>1"',
    'vmstats:"~>1"'
] %}

# TODO(mandre) Use packaged sensu plugins from centos-opstools for binary distro
# http://cbs.centos.org/koji/search?match=glob&type=package&terms=*sensu*
# NOTE(hrw): whois 5.0.0 requires Ruby 2.4+ while CentOS has 2.0
# NOTE(yoctozepto): pinning minitest for the same reason
RUN {%if base_package_type == 'rpm' %} gem install whois:"<5" minitest:"~>5.11.3" && {% endif %} sensu-install --plugins {{ sensu_plugins | customizable('plugins') | join (',') }}
{% endblock %}

{% block sensu_client_footer %}{% endblock %}
{% block footer %}{% endblock %}
